package com.hedl.studyandjava8.java_new.lambda.entity;

import com.hedl.studyandjava8.java_new.lambda.service.GreetingService;
import com.hedl.studyandjava8.java_new.lambda.service.MathOperation;

/**
 * @author Big Watermelon
 * @description
 * @date 2024/02/13/18:41
 */
public class Java8Tester_1 {
    private int operate(int a, int b, MathOperation mathOperation){
        return mathOperation.operation(a,b);
    }

    public static void main(String[] args) {
        Java8Tester_1 tester = new Java8Tester_1();
        //声明类型
        MathOperation addition = (int a, int b) -> a + b;

        //不用类型声明
        MathOperation subtraction = (a, b) -> a - b;

        //打括号中的返回语句
        MathOperation multiplication = (int a, int b) -> {
            return a * b;
        };

        //没有大括号及返回语句
        MathOperation division = (int a, int b) -> a / b;

        System.out.println("10 + 5 = " + tester.operate(10, 5, addition));
        System.out.println("10 - 5 = " + tester.operate(10, 5, subtraction));
        System.out.println("10 x 5 = " + tester.operate(10, 5, multiplication));
        System.out.println("10 / 5 = " + tester.operate(10, 5, division));

        //不用括号
        GreetingService greetService1 = message -> System.out.println("Hello "+message);

        //用括号
        GreetingService greetService2 = (message) ->System.out.println("Hello "+message);

        greetService1.sayMessage("Runoob");
        greetService2.sayMessage("Google");
    }
}
